import time

from selenium.webdriver.chrome import webdriver
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.microsoft import EdgeChromiumDriverManager

# """ 警告弹窗
# 1.打开浏览器驱动管理
EdgeIns = EdgeChromiumDriverManager().install()
# 2.创建谷歌浏览器对象
driver = webdriver.Edge(EdgeIns)
#  3.输入弹窗网页
# driver.get('file:///E:/Code/python/Python%E8%87%AA%E5%8A%A8%E5%8C%96/selenium/selenium-html/alert.html')
driver.get('http://113.45.147.167:9090/blog_login.html')
time.sleep(5)
# 4. 查找 + 点击 + 弹窗确认/取消
# driver.find_element(By.CSS_SELECTOR, '#tooltip').click()
# driver.find_element(By.CSS_SELECTOR, '#submit').click()
time.sleep(1)
alert = driver.switch_to.alert
time.sleep(1)
alert.accept()
time.sleep(1)
# 5.关闭浏览器
driver.quit()
# """

""" 确认弹窗
# 1.打开浏览器驱动管理
ChromeIns = ChromeDriverManager().install()
# 2.创建谷歌浏览器对象
driver = webdriver.Chrome(service=Service(ChromeIns))
#  3.输入弹窗网页
driver.get('file:///E:/Code/python/Python%E8%87%AA%E5%8A%A8%E5%8C%96/selenium/selenium-html/confirm.html')
time.sleep(1)
# 4. 查找 + 点击 + 弹窗确认/取消
driver.find_element(By.CSS_SELECTOR, 'body > input[type=button]').click()
time.sleep(1)
alert = driver.switch_to.alert
time.sleep(1)
# alert.accept()  # 确认
alert.dismiss() # 取消
time.sleep(1)
# 5.关闭浏览器
driver.quit()
"""

""" 提示弹窗
# 1.打开浏览器驱动管理
ChromeIns = ChromeDriverManager().install()
# 2.创建谷歌浏览器对象
driver = webdriver.Chrome(service=Service(ChromeIns))
#  3.输入弹窗网页
driver.get('file:///E:/Code/python/Python%E8%87%AA%E5%8A%A8%E5%8C%96/selenium/selenium-html/Prompt.html')
time.sleep(1)
# 4. 查找 + 点击 + 弹窗确认/取消
driver.find_element(By.CSS_SELECTOR, 'body > input[type=button]').click()
time.sleep(1)
alert = driver.switch_to.alert
alert.send_keys('hello world')
time.sleep(1)
alert.accept()  # 确认
# alert.dismiss() # 取消
time.sleep(1)
# 5.关闭浏览器
driver.quit()
"""
